//
//  ToolVariable.h
//  KindergartenDemo
//
//  Created by 李传铎 on 2020/11/8.
//  Copyright © 2020 李传铎. All rights reserved.
//

#ifndef ToolVariable_h
#define ToolVariable_h

static inline BOOL IsEmpty(id thing) {
    return thing == nil || [thing isEqual:[NSNull null]]
    || ([thing respondsToSelector:@selector(length)]
        && [(NSData *)thing length] == 0)
    || ([thing respondsToSelector:@selector(count)]
        && [(NSArray *)thing count] == 0);
}

#define  colorCode(str)  [UIColor colorFromHexCode:str]
#define  fontCount(str)  [UIFont systemFontOfSize:str]
#define  imageNameStr(str)  [UIImage imageNamed:str]

#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
///屏幕分辨率（5、5S、SE）
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : 0)
///屏幕分辨率（6、6S、7、8）
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : 0)
///屏幕分辨率（6P、6SP、7P、8P）
#define iPhoneP ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : 0)
///屏幕分辨率（XR）
#define iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : 0)
///屏幕分辨率（X、XS）
#define iPhoneXS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : 0)
///屏幕分辨率（XS_Max）
#define iPhoneXS_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : 0)

///异形全面屏
#define iPhoneX [PRMarketManager isIPhoneXType]

//**********************************************************************************************//

///屏宽
#define __kScreenWidth__            [[UIScreen mainScreen] bounds].size.width
///屏高
#define __kScreenHeight__           [[UIScreen mainScreen] bounds].size.height
///状态栏高
#define __kStatusBarHeight__        ([UIApplication sharedApplication].statusBarFrame.size.height)
///异形屏底部安全距离
#define __kTabbarSafeBottomMargin__  [PRMarketManager safeAreaInsetsBottom]
///导航栏高（包含状态栏）
#define __kNavigationBarHeight__    (__kStatusBarHeight__ + 44.f)
///tab高度
#define __kTabBarHeight__           (49.f + __kTabbarSafeBottomMargin__)
///内容高度（去除导航栏和tab）
#define __kContentHeight__          (__kScreenHeight__-__kNavigationBarHeight__-__kTabBarHeight__)
///内容高度（去除导航栏）
#define __kOriginalHeight__         (__kScreenHeight__-__kNavigationBarHeight__)
///内容高度（去除tab）
#define __kUnitaryHeight__          (__kScreenHeight__-__kTabBarHeight__)
///tabBarFrame大小
#define __kTabBarFrame__            CGRectMake(0, __kScreenHeight__-__kTabBarHeight__, __kScreenWidth__, __kTabBarHeight__)

//**********************************************************************************************//
///View 圆角和加边框
#define __kViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

///View 圆角
#define __kViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

#define  __kAdjustsScrollViewInsets_NO(scrollView,vc)\
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
if ([UIScrollView instancesRespondToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
[scrollView   performSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:") withObject:@(2)];\
} else {\
vc.automaticallyAdjustsScrollViewInsets = NO;\
}\
_Pragma("clang diagnostic pop") \
} while (0)

/* ********************获取frame大小********************* */
#define XOf(v)                    (v).frame.origin.x
#define YOf(v)                    (v).frame.origin.y
#define WIDTHOf(v)                (v).frame.size.width
#define HEIGHTOf(v)               (v).frame.size.height

#define MinX(v)                 CGRectGetMinX((v).frame)
#define MinY(v)                 CGRectGetMinY((v).frame)

#define MidX(v)                 CGRectGetMidX((v).frame)
#define MidY(v)                 CGRectGetMidY((v).frame)

#define MaxX(v)                 CGRectGetMaxX((v).frame)
#define MaxY(v)                 CGRectGetMaxY((v).frame)

#warning 待移除(不推荐使用)
//*************************待移除(不推荐使用)**************************************//

#define SCREEN_WIDTH          __kScreenWidth__
#define SCREEN_HEIGHT         __kScreenHeight__
// 比例高度
#define SCREEN_HEIGHT_iPhoneX        (iPhoneX ? 667 : SCREEN_HEIGHT)
#define SCALEW(x)  ([[UIScreen mainScreen] bounds].size.width*(x)/375.0)

#define  iPhone6P               iPhoneP
#define  isIphoneX_XS           iPhoneXS
#define  isIphoneXR_XSMax       iPhoneXS_Max


#define  StatusBarHeight                  __kStatusBarHeight__
#define  NavigationBarHeight              44.f
#define  TabbarHeight                     __kTabBarHeight__
#define  TabbarSafeBottomMargin           __kTabbarSafeBottomMargin__
#define  StatusBarAndNavigationBarHeight  __kNavigationBarHeight__


#define ViewBorderRadius(View, Radius, Width, Color)  __kViewBorderRadius(View, Radius, Width, Color)
#define ViewRadius(View, Radius) __kViewRadius(View, Radius)

#define  adjustsScrollViewInsets_NO(scrollView,vc) __kAdjustsScrollViewInsets_NO(scrollView,vc)




//*************************待移除(不推荐使用)**************************************//

#define SCREEN_WIDTH          __kScreenWidth__
#define SCREEN_HEIGHT         __kScreenHeight__
// 比例高度
#define SCREEN_HEIGHT_iPhoneX        (iPhoneX ? 667 : SCREEN_HEIGHT)
#define SCALEW(x)  ([[UIScreen mainScreen] bounds].size.width*(x)/375.0)

#define  iPhone6P               iPhoneP
#define  isIphoneX_XS           iPhoneXS
#define  isIphoneXR_XSMax       iPhoneXS_Max


#define  StatusBarHeight                  __kStatusBarHeight__
#define  NavigationBarHeight              44.f
#define  TabbarHeight                     __kTabBarHeight__
#define  TabbarSafeBottomMargin           __kTabbarSafeBottomMargin__
#define  StatusBarAndNavigationBarHeight  __kNavigationBarHeight__
#define  KStatusBottomBarHeight            (iPhoneX ? 70.f : 0.f)

#define ViewBorderRadius(View, Radius, Width, Color)  __kViewBorderRadius(View, Radius, Width, Color)
#define ViewRadius(View, Radius) __kViewRadius(View, Radius)

#define  adjustsScrollViewInsets_NO(scrollView,vc) __kAdjustsScrollViewInsets_NO(scrollView,vc)

/** RGB颜色 */
#define __kColor(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

#define __kColorAlpha(r,g,b,alp) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(alp)]

// rgb颜色转换（16进制->10进制）
#define __kColorFromHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define __kColorFromHexA(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]

//随机色
#define __kRandomColor__ [UIColor colorWithRed:(arc4random()%255)/255.0 green:(arc4random()%255)/255.0 blue:(arc4random()%255)/255.0 alpha:1]




#warning 待移除(不推荐使用)
//*************************待移除(不推荐使用)**************************************//

#define COLORRGBA(R, G, B, A)       __kColorAlpha(R,G,B,A)
#define COLORRGB(r,g,b)             __kColor(r,g,b)


#define RGBHexAlpha(rgbValue,a)     __kColorFromHexA(rgbValue,a)
#define RGBHex(rgbValue)            __kColorFromHex(rgbValue)

#define kRandomColor                __kRandomColor__

///App名称
#define __kAppName__ [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]
///bundle号
#define __kBundleId__ [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]
///版本号
#define __kVersion__  [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
///手机系统版本
#define __kSystemVersion__ [[[UIDevice currentDevice] systemVersion] floatValue]

#define __kUserDefaults__       [NSUserDefaults standardUserDefaults]
#define __kNotificationCenter__ [NSNotificationCenter defaultCenter]
///发送通知
#define __kPostNotification(name,obj) [__kNotificationCenter__ postNotificationName:name object:obj];

///判断是否是ios9
#define IOS9_OR_LATER (__kSystemVersion__ >= 9.0)
///判断是否是ios10
#define IOS10_OR_LATER (__kSystemVersion__ >= 10.0)
///判断是否是ios11
#define IOS11_OR_LATER (__kSystemVersion__ >= 11.0)
///判断是否是ios12
#define IOS12_OR_LATER (__kSystemVersion__ >= 12.0)
///判断是否是ios13
#define IOS13_OR_LATER (__kSystemVersion__ >= 13.0)

#define __kWeakSelf__        __weak typeof(self) weakSelf = self;
#define __kStrongSelf__      __strong typeof(weakSelf) strongSelf = weakSelf;
#define __kWeakSelf(type)    __weak typeof(type) weak##type = type;
#define __kStrongSelf(type)  __strong typeof(type) type = weak##type;


#define __kFormat(string)    [NSString stringWithFormat:@"%@",string]


///获取Image
#define IMG(NAME) [UIImage imageNamed:(NAME)]
#define OrigIMG(a) [IMG(a) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

///获得SB的vc  SB的name和vc的id
#define SBVC(name,vcId) [[UIStoryboard storyboardWithName:name bundle:[NSBundle bundleForClass:[self class]]] instantiateViewControllerWithIdentifier:vcId];



#define __kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || [str isEqualToString:@"NULL"] || [str isEqualToString:@"(null)"] || [str isEqualToString:@"<null>"] || [str length] < 1 ? YES : NO )


//重写NSLog,Debug模式下打印日志和当前行数
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif

#if DEBUG
#define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DLog( s, ... )
#endif

#warning 待移除(不推荐使用)
//*************************待移除(不推荐使用)**************************************//


#define PFVAPP_VERSION __kVersion__
#define kSystemVersion [[UIDevice currentDevice] systemVersion]

#define WEAKSELF    __kWeakSelf__
#define STRONGSELF  __kStrongSelf__

#define Format(string) __kFormat(string)

#define kStringIsEmpty(str) __kStringIsEmpty(str)

#define SYSTEMFONT(FONTSIZE)    [UIFont systemFontOfSize:FONTSIZE]
#define __kSize(ptSize) [[PRMarketManager sharedPRMarketManager] translationSize:(ptSize*2.0)]
#define __kCGSizeMake(ptWidth,ptHeight) CGSizeMake(__kSize(ptWidth), __kSize(ptHeight))

#define __kCGRectMake(ptX,ptY,ptWidth,ptHeight) CGRectMake(__kSize(ptX), __kSize(ptY), __kSize(ptWidth), __kSize(ptHeight))

#define __kFont(ptSize) [UIFont systemFontOfSize:__kSize(ptSize)]

#define __kBoldFont(ptSize) [UIFont boldSystemFontOfSize:__kSize(ptSize)]
#endif /* ToolVariable_h */
